package com.bethinner.utils;

import android.content.Context;

import com.bethinner.dao.LocationDao;
import com.bethinner.dao.TestServiceDao;
import com.bethinner.demo.Location;
import com.bethinner.demo.TestService;

import java.util.List;

/**
 * Created by bethinner on 11/12/15.
 */
public class TestServiceHelper implements DaoHelperInterface{

    public static TestServiceHelper instance;
    private TestServiceDao testServiceDao;

    public TestServiceHelper(Context context) {
        try {
            testServiceDao = DbUtils.getDaoSession(context, "database_name.db").getTestServiceDao();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    public static TestServiceHelper getInstance(Context context) {
        if (instance == null) {
            instance = new TestServiceHelper(context);
        }

        return instance;
    }
    @Override
    public <T> void addData(T data) {
        if (testServiceDao != null && data != null) {
            testServiceDao.insertOrReplace((TestService) data);
        }
    }

    @Override
    public <T> void updateData(T data) {
        if (testServiceDao != null && data != null) {
            testServiceDao.update((TestService) data);
        }
    }

    @Override
    public void deleteData(Long id) {
        if (null != testServiceDao && null != id) {
            testServiceDao.deleteByKey(id);
        }
    }

    @Override
    public TestService getDataById(Long id) {
        if (null != testServiceDao && null != id) {
            return testServiceDao.load(id);
        }
        return null;
    }

    @Override
    public List<TestService> getAllData() {
        if (null != testServiceDao) {
            return testServiceDao.loadAll();
        }
        return null;
    }

    @Override
    public boolean hasKey(Long id) {
        return false;
    }

    @Override
    public long getTotalCount() {
        return 0;
    }

    @Override
    public void deleteAll() {
        if (testServiceDao != null) {
            testServiceDao.deleteAll();
        }
    }
}
